package com.qf.huigou.listener;

import com.qf.huigou.commons.SystemParamTool;
import com.qf.huigou.service.SystemParamService;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

/**
 * @version 1.8.0_131
 * @Author WangYiZhu
 * @Email 2641956765@qq.com
 * @Time 2022/12/08 16:26
 */

@WebListener
public class InitParamListener implements ServletContextListener {


    @Override
    public void contextInitialized(ServletContextEvent event) {
        ServletContext context=event.getServletContext();
        WebApplicationContext wac= WebApplicationContextUtils.getWebApplicationContext(context);
        SystemParamService paramService= wac.getBean(SystemParamService.class);
        String staticSource= paramService.findSystemParamValueByName(SystemParamTool.STATIC_SOURCE);
        String mainImage= paramService.findSystemParamValueByName(SystemParamTool.MAIN_IMAGE);
        String mainLogo= paramService.findSystemParamValueByName(SystemParamTool.MAIN_LOGO);
        String smallLogo= paramService.findSystemParamValueByName(SystemParamTool.SMALL_LOGO);

        context.setAttribute("static_source",staticSource);
        context.setAttribute("main_img",mainImage);
        context.setAttribute("main_logo",mainLogo);
        context.setAttribute("small_logo",smallLogo);
        System.out.println("初始化完成....");


    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {

    }
}
